package cn.tedu.smartos.admin.controller;

import cn.tedu.smartos.admin.pojo.dto.*;
import cn.tedu.smartos.admin.pojo.vo.NoticeVO;
import cn.tedu.smartos.admin.pojo.vo.RegionVO;
import cn.tedu.smartos.admin.service.AdminService;
import cn.tedu.smartos.base.response.JsonResult;
import cn.tedu.smartos.baseuser.pojo.vo.UserVO;
import cn.tedu.smartos.admin.pojo.vo.VolunteerVO;
import com.github.pagehelper.PageInfo;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "02.管理员模块")
@Slf4j
@RestController
@RequestMapping("/api/v1/admins/")
public class AdminController {
    @Autowired
    private AdminService adminService;

    /**
     * 01用户管理
     */
    @ApiOperation("用户列表")
    @ApiOperationSupport(order = 10)
    @GetMapping("list")
    public JsonResult list(@RequestParam(defaultValue = "1") Integer pageNum,
                           @RequestParam(defaultValue = "10") Integer pageSize) {
        log.debug("开始处理【用户列表】的请求,参数{},{}",pageNum,pageSize);
        PageInfo<UserVO> userList = adminService.list(pageNum,pageSize);
        return JsonResult.ok(userList);
    }
    @ApiOperation("用户详情")
    @ApiOperationSupport(order = 20)
    @GetMapping("detail")
    public JsonResult detail(@RequestParam Long userId) {
        log.debug("开始处理【用户详情】的请求,参数{}",userId);
        UserVO user = adminService.detail(userId);
        return JsonResult.ok(user);
    }
    @ApiOperation("用户删除")
    @ApiOperationSupport(order = 30)
    @PostMapping("delete")
    public JsonResult delete(@RequestBody List<Long> userIds) {
        log.debug("开始处理【用户删除】的请求,参数{}",userIds);
        adminService.delete(userIds);
        return JsonResult.ok();
    }
    @ApiOperation("用户信息修改")
    @ApiOperationSupport(order = 40)
    @PostMapping("update")
    public JsonResult update(@RequestBody AdminUpdateParam updateParam) {
        log.debug("开始处理【用户信息修改】的请求,参数{}",updateParam);
        adminService.update(updateParam);
        return JsonResult.ok();
    }
    @ApiOperation("添加用户或管理员")
    @ApiOperationSupport(order = 50)
    @PostMapping("add")
    public JsonResult add(@RequestBody AdminAddParam addParam) {
        log.debug("开始处理【添加用户或管理员】的 请求,参数{}",addParam);
        adminService.add(addParam);
        return JsonResult.ok();
    }
    @ApiOperation("重置密码")
    @ApiOperationSupport(order = 60)
    @PostMapping("reset-password")
    public JsonResult resetPassword(@RequestBody AdminResetPasswordParam param) {
        log.debug("开始处理【重置密码】的请求,参数{}", param.getUserId());
        adminService.resetPassword(param.getUserId());
        return JsonResult.ok();
    }
//————————————————————————————————————————————————————————————————————————————

    /**
     * 02志愿者管理
     */
    @ApiOperation("查询所有志愿者")
    @ApiOperationSupport(order = 100)
    @GetMapping("volunteer/list")
    public JsonResult volunteerList(@RequestParam(defaultValue = "1") Integer pageNum,
                                    @RequestParam(defaultValue = "10") Integer pageSize) {
        log.debug("开始处理【查询所有志愿者】的请求,参数{},{}",pageNum,pageSize);
        PageInfo<VolunteerVO> pageInfo = adminService.volunteerList(pageNum, pageSize);
        return JsonResult.ok(pageInfo);
    }
    @ApiOperation("查询待自己审核的志愿者")
    @ApiOperationSupport(order = 110)
    @GetMapping("volunteer/waitAudit")
    public JsonResult waitAudit(@RequestParam Long auditAdminId,
                                @RequestParam(defaultValue = "1") Integer pageNum,
                                @RequestParam(defaultValue = "10") Integer pageSize){
        log.debug("开始处理【查询待自己审核的志愿者】的请求,参数{},{},{}",auditAdminId,pageNum,pageSize);
        PageInfo<VolunteerVO> pageInfo = adminService.waitAudit(auditAdminId,pageNum,pageSize);
        return JsonResult.ok(pageInfo);
    }
    @ApiOperation("审核志愿者")
    @ApiOperationSupport(order = 120)
    @PostMapping("volunteer/audit")
    public JsonResult audit(@RequestBody VolunteerAuditParam auditParam){
        log.debug("开始处理【审核志愿者】的请求,参数{}",auditParam);
        adminService.audit(auditParam);
        return JsonResult.ok();
    }
    @ApiOperation("查看志愿者详情")
    @ApiOperationSupport(order = 130)
    @GetMapping("volunteer/detail")
    public JsonResult volunteerDetail(Long userId){
        log.debug("开始处理【查看志愿者详情】的请求,参数{}",userId);
        VolunteerVO volunteerVO = adminService.volunteerDetail(userId);
        return JsonResult.ok(volunteerVO);
    }

//——————————————————————————————————————————————————————————————————————————
    /**
     * 03公告管理
     */
    @ApiOperation("所有发布公告列表")
    @ApiOperationSupport(order = 200)
    @GetMapping("notice/list")
    public JsonResult noticeList(@RequestParam(defaultValue = "1") Integer pageNum,
                                 @RequestParam(defaultValue = "10") Integer pageSize){
        log.debug("开始处理【公告列表】的请求,参数{},{}",pageNum,pageSize);
        PageInfo<NoticeVO> pageInfo = adminService.noticeList(pageNum, pageSize);
        return JsonResult.ok(pageInfo);
    }
    @ApiOperation("删除公告(可批量)")
    @ApiOperationSupport(order = 210)
    @PostMapping("notice/delete")
    public JsonResult deleteNotice(@RequestBody List<Long> noticeIds){
        log.debug("开始处理【删除公告】的请求,参数{}",noticeIds);
        adminService.deleteNotice(noticeIds);
        return JsonResult.ok();
    }
    @ApiOperation("发布公告")
    @ApiOperationSupport(order = 220)
    @PostMapping("notice/add")
    public JsonResult addNotice(@RequestBody NoticeAddParam addParam){
        log.debug("开始处理【发布公告】的请求,参数{}",addParam);
        adminService.addNotice(addParam);
        return JsonResult.ok();
    }
    @ApiOperation("修改公告")
    @ApiOperationSupport(order = 230)
    @PostMapping("notice/update")
    public JsonResult updateNotice(@RequestBody NoticeUpdateParam updateParam){
        log.debug("开始处理【修改公告】的请求,参数{}",updateParam);
        adminService.updateNotice(updateParam);
        return JsonResult.ok();
    }
    @ApiOperation("查看公告详情")
    @ApiOperationSupport(order = 240)
    @GetMapping("notice/detail")
    public JsonResult noticeDetail(Long noticeId){
        log.debug("开始处理【查看公告详情】的请求,参数{}",noticeId);
        NoticeVO noticeVO = adminService.noticeDetail(noticeId);
        return JsonResult.ok(noticeVO);
    }

//——————————————————————————————————————————————————————————————————————————
    /**
     * 04区域管理
     */
    @ApiOperation("区域列表")
    @ApiOperationSupport(order = 300)
    @GetMapping("region/list")
    public JsonResult regionList(@RequestParam(defaultValue = "1") Integer pageNum,
                                 @RequestParam(defaultValue = "10") Integer pageSize){
        log.debug("开始处理【区域列表】的请求,参数{},{}",pageNum,pageSize);
        PageInfo<RegionVO> pageInfo = adminService.regionList(pageNum, pageSize);
        return JsonResult.ok(pageInfo);
    }
    @ApiOperation("添加区域")
    @ApiOperationSupport(order = 310)
    @PostMapping("region/add")
    public JsonResult addRegion(@RequestBody RegionParam addParam){
        log.debug("开始处理【添加区域】的请求,参数{}",addParam);
        adminService.addRegion(addParam);
        return JsonResult.ok();
    }
    @ApiOperation("删除区域")
    @ApiOperationSupport(order = 320)
    @PostMapping("region/delete")
    public JsonResult deleteRegion(@RequestBody List<Integer> regionIds){
        log.debug("开始处理【删除区域】的请求,参数{}",regionIds);
        adminService.deleteRegion(regionIds);
        return JsonResult.ok();
    }
    @ApiOperation("区域详情")
    @ApiOperationSupport(order = 330)
    @GetMapping("region/detail")
    public JsonResult regionDetail(Integer regionId){
        log.debug("开始处理【区域详情】的请求,参数{}",regionId);
        RegionVO regionVO = adminService.regionDetail(regionId);
        return JsonResult.ok(regionVO);
    }
    @ApiOperation("绑定管理员到区域")
    @ApiOperationSupport(order = 340)
    @PostMapping("region/bind")
    public JsonResult bind(Long adminId,Integer regionId) {
        log.debug("开始处理【绑定管理员到区域】的请求,参数{},{}",adminId,regionId);
        adminService.adminBind(adminId,regionId);
        return JsonResult.ok();
    }
    @ApiOperation("解绑管理员与区域")
    @ApiOperationSupport(order = 350)
    @PostMapping("region/unbind")
    public JsonResult unbind(Long adminRegionId) {
        log.debug("开始处理【解绑管理员与区域】的请求,参数{}",adminRegionId);
        adminService.adminUnbind(adminRegionId);
        return JsonResult.ok();
    }

//——————————————————————————————————————————————————————————————————————————————————

}
